﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace PingYou
{
    class DataTableOp
    {
        #region 构建DataTable
        private DataTable GetDataTable()
        {
            DataTable myIdDt = new DataTable();
            try
            {
                DataRow myNewDr = null;
                myIdDt.Columns.AddRange(new DataColumn[] {
                new DataColumn("ID"),
                new DataColumn("FullName"),
                //分类
                new DataColumn("CategoryID"),
                //分类
                new DataColumn("Score",typeof(int)),
                new DataColumn("StartScore",typeof(string)),
                new DataColumn("EndScore",typeof(string))
                });
                myNewDr = myIdDt.NewRow();
                myNewDr["ID"] = "10000001";
                myNewDr["FullName"] = "demo001";
                myNewDr["CategoryID"] = "1";
                myNewDr["Score"] = 95;
                myNewDr["StartScore"] = "91.5";
                myNewDr["EndScore"] = "97.5";
                myIdDt.Rows.Add(myNewDr);

                myNewDr = myIdDt.NewRow();
                myNewDr["ID"] = "10000002";
                myNewDr["FullName"] = "demo002";
                myNewDr["CategoryID"] = "1";
                myNewDr["Score"] = 90;
                myNewDr["StartScore"] = "86.5";
                myNewDr["EndScore"] = "91.4";
                myIdDt.Rows.Add(myNewDr);

                myNewDr = myIdDt.NewRow();
                myNewDr["ID"] = "10000003";
                myNewDr["FullName"] = "demo003";
                myNewDr["CategoryID"] = "1";
                myNewDr["Score"] = 99;
                myNewDr["StartScore"] = "83.5";
                myNewDr["EndScore"] = "86.4";
                myIdDt.Rows.Add(myNewDr);

                myNewDr = myIdDt.NewRow();
                myNewDr["ID"] = "10000004";
                myNewDr["FullName"] = "demo004";
                myNewDr["CategoryID"] = "0";
                myNewDr["Score"] = 98;
                myNewDr["StartScore"] = "91.5";
                myNewDr["EndScore"] = "97.5";
                myIdDt.Rows.Add(myNewDr);

                myNewDr = myIdDt.NewRow();
                myNewDr["ID"] = "10000005";
                myNewDr["FullName"] = "demo005";
                myNewDr["CategoryID"] = "2";
                myNewDr["Score"] = 70;
                myNewDr["StartScore"] = "91.5";
                myNewDr["EndScore"] = "97.5";

                myIdDt.Rows.Add(myNewDr);

                myNewDr = myIdDt.NewRow();
                myNewDr["ID"] = "10000006";
                myNewDr["FullName"] = "demo006";
                myNewDr["CategoryID"] = "0";
                myNewDr["Score"] = 75;
                myNewDr["StartScore"] = "91.5";
                myNewDr["EndScore"] = "97.5";
                myIdDt.Rows.Add(myNewDr);
            }
            catch (Exception myEx)
            {
                Common.WriteLogErr("myDataTableOp-GetDataTable:" + myEx.Message);
            }
            return myIdDt;
        }
        #endregion

        #region 未分类的数据查询方法
        public void NoFenLei()
        {
            try
            {
                //string paramMail = "2603956901@qq.com";
                //bool IsMatchMail = Common.IsMatchMail(paramMail);
                //if(IsMatchMail)
                //{

                //}

                //new DataTableOp().DataTableRemove();
                //new DataTableOp().GetMaxMinDt();

                //求和
                //new DataTableOp().GetDataTableSum();


                //string dt = DateTime.Now.ToString("yyMMdd");


                //string  dbCode = "190531005";
                //dbCode = "19053000122020200";
                //string newCode = DataTableOp.GetCode(0, dbCode);

                //string newCode1 = DataTableOp.GetCode(1, dbCode);



                //string temp = dbCode.Substring(6, 3);


                //int curIndex = Convert.ToInt32(temp);


                //string strTemp = "语文,数学,英语";
                //int iResult = strTemp.IndexOf("语文(选)");
                //string tt = "1";

                //DateTime myDateTime = Convert.ToDateTime("2019-06-09");
                //int dt = myDateTime.DayOfWeek.GetHashCode();
                //myDateTime = Convert.ToDateTime("2019-06-15");
                //dt = myDateTime.DayOfWeek.GetHashCode();
                //string tt = "";


                //double dParam = 874845;
                //string targetParam = dParam.ToString();
                //targetParam = string.Format("{0:F}", dParam);

                //dParam = 874845.0001;

                //targetParam = string.Format("{0:F}", dParam);

                //dParam = 985.21455421;
                //targetParam = string.Format("{0:F}", dParam);

                //string tt = "";



                //string myDateTime = "2019.06";
                //myDateTime = "2019/06";
                //myDateTime = "2019-06";
                //myDateTime = "2019年06月01日";
                //string myTempDateTime = string.Empty;
                //myTempDateTime = myDateTime.Replace(".", "-").Replace("/", "-").Replace("年", "-").Replace("月", "-").Replace("日", "");

                //try
                //{
                //    int iLen = myTempDateTime.Split('-').Length;
                //    if (iLen != 3)
                //    {
                //        var tt = 2;
                //    }
                //    myTempDateTime = Convert.ToDateTime(myDateTime).ToString("yyyy-MM-dd");
                //}
                //catch (Exception myEx)
                //{

                //}


                //使用字典进行循环操作
                //Dictionary<string, object> myParam = new Dictionary<string, object>();
                //myParam.Add("ID1", "1");
                //myParam.Add("ID2", "2");
                //myParam.Add("ID3", "3");
                //myParam.Add("ID4", "4");
                //myParam.Add("ID5", "5");
                //myParam.Add("ID6", "6");
                //myParam.Add("ID7", "7");

                //int len = myParam.Keys.Count(); ;
                // string [] myParamArr = myParam.Keys.ToArray();
                //for (int i = 0; i < len; i++)
                //{
                //    object myObj = myParam[myParamArr[i]];
                //}

                #region 判断当前传递的参数是否在枚举当中

                //string a1 = "体艺选修课";

                //foreach (string s in Enum.GetNames(typeof(NatureType)))
                //{
                //    if (a1 == s)
                //    {
                //        int iNatureType = Enum.Parse(typeof(NatureType), s).GetHashCode();
                //    }
                //}
                #endregion

                //string tempUnitIDs = "fee2e3beff2143dda56159e5b107c128,10000258,10000257,10000256,10000255,10000254,10000253,10000252,10000251,10000250,10000249,10000248,10000247,10000246,10000245,10000244,10000243,10000242,10000241,10000240,10000239,10000238,10000237,10000236,10000235,10000234,10000233,10000232,10000231,10000230,10000229,10000228,10000227,10000226,10000225,10000224,10000223,10000222,10000221,10000220,10000219,10000218,10000217,10000216,10000215,10000214,10000213,10000212,10000211,10000210,10000209,10000208,10000207,10000206,10000205,10000204,10000203,10000202,10000201,10000200,10000199,10000198,10000197,10000196,10000195,10000194,10000193,10000192,10000191,10000190,10000189,10000188,10000187,10000186,10000185,10000184,10000183,10000182,10000181,10000180,10000179,10000178,10000177,10000176,10000175,10000174,10000173,10000172,10000171,10000170,10000169,10000168,10000167,10000166,10000165,10000162,10000161,10000160,10000159,10000158,10000157,10000155,10000154,10000153,10000152,10000151,10000150,10000149,10000148,10000147,10000146,10000145,10000144,10000143,10000142,10000141,10000140,10000139,10000138,10000137,10000136,10000133,10000132,10000131,10000130,10000120,10000119,10000118,10000117,10000116,10000115,10000114,10000113,10000112,10000111,10000110,10000108,10000107,10000105,10000104,10000101,10000100,10000099,10000096,10000093,10000092,10000091,10000090,10000085,10000084,10000081,10000080,10000079,10000078,10000077,10000076,10000072,10000069,10000068,10000061,10000060,10000059,10000058,10000057,10000053,10000052,10000049,10000045,10000037,10000031,10000030,10000027,10000026,10000023,10000022,10000019,10000018,10000015,10000014,10000013,10000003,10000002";
                //if (tempUnitIDs.IndexOf('\'')<0) {
                //    tempUnitIDs = "'" + tempUnitIDs.Replace(",", "','") + "'";    
                //}
                //string result = tempUnitIDs;

                // 周次时间
                //DateTime myDateTime = DateTime.Now;
                //int tt = myDateTime.DayOfWeek.GetHashCode();
                //int t1 = 0;



                /***********时间范围过滤 start****************************/
                //try
                //{
                //    DataTable myDt = new DataTableOp().GetDataTableOfDate();
                //    DataRow[] myTempDrs = myDt.Select("StartDate <='2019-10-06' and EndDate >='2019-10-06'");
                //    //DataRow[] myTempDrs = myDt.Select("CONVERT(NVARCHAR(100), StartDate,23) >='2019-10-06' and CONVERT(NVARCHAR(100), EndDate,23) >='2019-10-06'");
                //    DataTable myTempDt = null;
                //    if (myTempDrs.Length > 0)
                //    {
                //        myTempDt = myTempDrs.CopyToDataTable();
                //    }
                //    else
                //    {
                //        myTempDt = myDt.Clone();
                //    }
                //}
                //catch (Exception myEx)
                //{
                //    string result = myEx.Message;
                //}
                /***********时间范围过滤 end****************************/

            }
            catch (Exception myEx)
            {
                throw myEx;
            }
        }
        #endregion

        public DataTable GetDataTableOther()
        {
            DataTable myIdDt = new DataTable();
            try
            {
                DataRow myNewDr = null;
                myIdDt.Columns.AddRange(new DataColumn[] {
                new DataColumn("ID"),
                new DataColumn("FullName"),
                //分类
                new DataColumn("CategoryID")
                });
                myNewDr = myIdDt.NewRow();
                myNewDr["ID"] = "10000001";
                myNewDr["FullName"] = "demo001";
                myNewDr["CategoryID"] = "2";
                myNewDr["GradeNames"] = "年级,二年级";
                myIdDt.Rows.Add(myNewDr);

                myNewDr = myIdDt.NewRow();
                myNewDr["ID"] = "10000002";
                myNewDr["FullName"] = "demo002";
                myNewDr["CategoryID"] = "1";
                myNewDr["GradeNames"] = "五年级,六年级";

                myIdDt.Rows.Add(myNewDr);

                myNewDr = myIdDt.NewRow();
                myNewDr["ID"] = "10000003";
                myNewDr["FullName"] = "demo003";
                myNewDr["CategoryID"] = "0";
                myNewDr["GradeNames"] = "四年级,六年级";
                myIdDt.Rows.Add(myNewDr);

                myNewDr = myIdDt.NewRow();
                myNewDr["ID"] = "10000004";
                myNewDr["FullName"] = "demo004";
                myNewDr["CategoryID"] = "3";
                myNewDr["GradeNames"] = "三年级,五年级";
                myIdDt.Rows.Add(myNewDr);

                myNewDr = myIdDt.NewRow();
                myNewDr["ID"] = "10000005";
                myNewDr["FullName"] = "demo005";
                myNewDr["CategoryID"] = "2";
                myNewDr["GradeNames"] = "一年级,四年级";

                myIdDt.Rows.Add(myNewDr);

                myNewDr = myIdDt.NewRow();
                myNewDr["ID"] = "10000006";
                myNewDr["FullName"] = "demo006";
                myNewDr["CategoryID"] = "3";
                myNewDr["GradeNames"] = "一年级,三年级";
                myIdDt.Rows.Add(myNewDr);

            }
            catch (Exception myEx)
            {
                Common.WriteLogErr("myDataTableOp-GetDataTable:" + myEx.Message);
            }
            return myIdDt;
        }
        public static DataTable GetDataTableOtherV2()
        {
            DataTable myIdDt = new DataTable();
            try
            {
                DataRow myNewDr = null;
                myIdDt.Columns.AddRange(new DataColumn[] {
                new DataColumn("ID"),
                new DataColumn("FullName"),
                //分类
                new DataColumn("CategoryID"),
                new DataColumn("GradeNames")
                });
                myNewDr = myIdDt.NewRow();
                myNewDr["ID"] = "10000001";
                myNewDr["FullName"] = "demo001";
                myNewDr["CategoryID"] = "2";
                myNewDr["GradeNames"] = "年级,二年级";
                myIdDt.Rows.Add(myNewDr);

                myNewDr = myIdDt.NewRow();
                myNewDr["ID"] = "10000002";
                myNewDr["FullName"] = "demo002";
                myNewDr["CategoryID"] = "1";
                myNewDr["GradeNames"] = "五年级,六年级";

                myIdDt.Rows.Add(myNewDr);

                //myNewDr = myIdDt.NewRow();
                //myNewDr["ID"] = "10000003";
                //myNewDr["FullName"] = "demo003";
                //myNewDr["CategoryID"] = "0";
                //myNewDr["GradeNames"] = "四年级,六年级";
                //myIdDt.Rows.Add(myNewDr);

                //myNewDr = myIdDt.NewRow();
                //myNewDr["ID"] = "10000004";
                //myNewDr["FullName"] = "demo004";
                //myNewDr["CategoryID"] = "3";
                //myNewDr["GradeNames"] = "三年级,五年级";
                //myIdDt.Rows.Add(myNewDr);

                //myNewDr = myIdDt.NewRow();
                //myNewDr["ID"] = "10000005";
                //myNewDr["FullName"] = "demo005";
                //myNewDr["CategoryID"] = "2";
                //myNewDr["GradeNames"] = "一年级,四年级";

                //myIdDt.Rows.Add(myNewDr);

                //myNewDr = myIdDt.NewRow();
                //myNewDr["ID"] = "10000006";
                //myNewDr["FullName"] = "demo006";
                //myNewDr["CategoryID"] = "3";
                //myNewDr["GradeNames"] = "一年级,三年级";
                //myIdDt.Rows.Add(myNewDr);

            }
            catch (Exception myEx)
            {
                //Common.WriteLogErr("myDataTableOp-GetDataTable:" + myEx.Message);
            }
            return myIdDt;
        }

        #region DataTable 数据条件排除  Not in
        public void DataTableRemove()
        {
            try
            {
                DataTable myDt = this.GetDataTable();
                DataTable myDtOther = this.GetDataTableOther();
                DataRow[] myDrs = myDt.Select(string.Format("{0}='{1}'", "CategoryID", "1"));
                if (myDrs.Length > 0)
                {
                    myDt = myDrs.CopyToDataTable();
                }

                DataRow[] myDrs1 = myDtOther.Select(string.Format("{0}='{1}'", "CategoryID", "1"));
                int len = myDrs1.Length;
                string[] exclude = new string[len];
                for (int i = 0; i < len; i++)
                {
                    exclude[i] = myDrs1[i]["ID"].ToString();
                }

                DataTable result = myDt.AsEnumerable().Where(r => !exclude.Contains(r["ID"])).CopyToDataTable();
            }
            catch (Exception myEx)
            {
                Common.WriteLogErr(myEx.Message);
            }
        }
        #endregion

        #region DataTable 求最大值最小值
        /// <summary>
        /// DataTable 求最大值最小值
        /// </summary>
        /// <returns></returns>
        public DataTable GetMaxMinDt()
        {
            DataTable myIdDt = new DataTable();
            try
            {
                DataRow myNewDr = null;
                myIdDt.Columns.AddRange(new DataColumn[] {
                new DataColumn("ID"),
                new DataColumn("FullName"),
                new DataColumn("Index"),
                //分类
                new DataColumn("CategoryID",typeof(int))
                });
                myNewDr = myIdDt.NewRow();
                myNewDr["ID"] = "10000001";
                myNewDr["FullName"] = "demo001";
                myNewDr["Index"] = 6;
                myNewDr["CategoryID"] = 2;
                myIdDt.Rows.Add(myNewDr);

                myNewDr = myIdDt.NewRow();
                myNewDr["ID"] = "10000002";
                myNewDr["FullName"] = "demo002";
                myNewDr["Index"] = 4;
                myNewDr["CategoryID"] = 1;

                myIdDt.Rows.Add(myNewDr);

                myNewDr = myIdDt.NewRow();
                myNewDr["ID"] = "10000003";
                myNewDr["FullName"] = "demo003";
                myNewDr["Index"] = 5;
                myNewDr["CategoryID"] = 0;
                myIdDt.Rows.Add(myNewDr);

                myNewDr = myIdDt.NewRow();
                myNewDr["ID"] = "10000002";
                myNewDr["FullName"] = "demo004";
                myNewDr["Index"] = 3;
                myNewDr["CategoryID"] = 3;
                myIdDt.Rows.Add(myNewDr);

                myNewDr = myIdDt.NewRow();
                myNewDr["ID"] = "10000005";
                myNewDr["FullName"] = "demo005";
                myNewDr["Index"] = 7;
                myNewDr["CategoryID"] = 2;

                myIdDt.Rows.Add(myNewDr);

                myNewDr = myIdDt.NewRow();
                myNewDr["ID"] = "10000006";
                myNewDr["FullName"] = "demo006";
                myNewDr["Index"] = 1;
                myNewDr["CategoryID"] = 3;
                myIdDt.Rows.Add(myNewDr);

                int i = 0;
                object myObj = myIdDt.Compute("Max(Index)", "");
                myObj = myIdDt.Compute("Min(Index)", "");
                if (myObj != null)
                {
                    try
                    {
                        i = Convert.ToInt32(myObj.ToString());
                    }
                    catch (Exception myEx)
                    {
                        throw myEx;
                    }
                }

            }
            catch (Exception myEx)
            {
                Common.WriteLogErr("myDataTableOp-GetDataTable:" + myEx.Message);
            }
            return myIdDt;
        }

        public DataTable GetMaxMinDtv2()
        {
            DataTable result = null;
            try
            {

                DataTable myIdDt = GetDataTable();
                DataRow[] myDrs = myIdDt.Select(string.Format("CONVERT( {0},'System.Double')<={2} AND {2}<= CONVERT( {1},'System.Double')", "StartScore", "EndScore", Convert.ToDouble("96"), "EndScore" + " DESC "));
                if (myDrs.Length > 0)
                {
                    result = myDrs.CopyToDataTable();
                }
            }
            catch (Exception myEx)
            {
                Common.WriteLogErr("myDataTableOp-GetDataTable:" + myEx.Message);
            }
            return result;
        }
        #endregion

        #region DataTable 求和
        public DataTable GetDataTableSum()
        {
            DataTable myIdDt = new DataTable();
            try
            {
                DataRow myNewDr = null;
                myIdDt.Columns.AddRange(new DataColumn[] {
                new DataColumn("ID"),
                new DataColumn("FullName"),
                //分类
                new DataColumn("CategoryID",typeof(int))
                });
                myNewDr = myIdDt.NewRow();
                myNewDr["ID"] = "10000001";
                myNewDr["FullName"] = "demo001";
                myNewDr["CategoryID"] = 2;
                myIdDt.Rows.Add(myNewDr);

                myNewDr = myIdDt.NewRow();
                myNewDr["ID"] = "10000002";
                myNewDr["FullName"] = "demo002";
                myNewDr["CategoryID"] = 1;

                myIdDt.Rows.Add(myNewDr);

                myNewDr = myIdDt.NewRow();
                myNewDr["ID"] = "10000003";
                myNewDr["FullName"] = "demo003";
                myNewDr["CategoryID"] = 0;
                myIdDt.Rows.Add(myNewDr);

                myNewDr = myIdDt.NewRow();
                myNewDr["ID"] = "10000002";
                myNewDr["FullName"] = "demo004";
                myNewDr["CategoryID"] = 3;
                myIdDt.Rows.Add(myNewDr);

                myNewDr = myIdDt.NewRow();
                myNewDr["ID"] = "10000005";
                myNewDr["FullName"] = "demo005";
                myNewDr["CategoryID"] = 2;

                myIdDt.Rows.Add(myNewDr);

                myNewDr = myIdDt.NewRow();
                myNewDr["ID"] = "10000006";
                myNewDr["FullName"] = "demo006";
                myNewDr["CategoryID"] = 3;
                myIdDt.Rows.Add(myNewDr);

                int i = 0;
                object myObj = myIdDt.Compute("Sum(CategoryID)", "ID='10000002'");
                if (myObj != null)
                {
                    try
                    {
                        i = Convert.ToInt32(myObj.ToString());
                    }
                    catch (Exception myEx)
                    {
                        throw myEx;
                    }
                }

            }
            catch (Exception myEx)
            {
                Common.WriteLogErr("myDataTableOp-GetDataTable:" + myEx.Message);
            }
            return myIdDt;
        }
        #endregion

        #region DataTable 求平均值
        public DataTable GetDataTableAvg()
        {
            DataTable myIdDt = new DataTable();
            try
            {
                DataRow myNewDr = null;
                myIdDt.Columns.AddRange(new DataColumn[] {
                new DataColumn("ID"),
                new DataColumn("FullName"),
                //分类
                new DataColumn("CategoryID",typeof(int))
                });
                myNewDr = myIdDt.NewRow();
                myNewDr["ID"] = "10000001";
                myNewDr["FullName"] = "demo001";
                myNewDr["CategoryID"] = 2;
                myIdDt.Rows.Add(myNewDr);

                myNewDr = myIdDt.NewRow();
                myNewDr["ID"] = "10000002";
                myNewDr["FullName"] = "demo002";
                myNewDr["CategoryID"] = 1;

                myIdDt.Rows.Add(myNewDr);

                myNewDr = myIdDt.NewRow();
                myNewDr["ID"] = "10000003";
                myNewDr["FullName"] = "demo003";
                myNewDr["CategoryID"] = 0;
                myIdDt.Rows.Add(myNewDr);

                myNewDr = myIdDt.NewRow();
                myNewDr["ID"] = "10000002";
                myNewDr["FullName"] = "demo004";
                myNewDr["CategoryID"] = 3;
                myIdDt.Rows.Add(myNewDr);

                myNewDr = myIdDt.NewRow();
                myNewDr["ID"] = "10000005";
                myNewDr["FullName"] = "demo005";
                myNewDr["CategoryID"] = 100;
                myIdDt.Rows.Add(myNewDr);

                myNewDr = myIdDt.NewRow();
                myNewDr["ID"] = "10000005";
                myNewDr["FullName"] = "demo005";
                myNewDr["CategoryID"] = 125;
                myIdDt.Rows.Add(myNewDr);

                myNewDr = myIdDt.NewRow();
                myNewDr["ID"] = "10000006";
                myNewDr["FullName"] = "demo006";
                myNewDr["CategoryID"] = 3;
                myIdDt.Rows.Add(myNewDr);

                myNewDr = myIdDt.NewRow();
                myNewDr["ID"] = "10000006";
                myNewDr["FullName"] = "demo006";
                myNewDr["CategoryID"] = 10;
                myIdDt.Rows.Add(myNewDr);

                myNewDr = myIdDt.NewRow();
                myNewDr["ID"] = "10000006";
                myNewDr["FullName"] = "demo006";
                myNewDr["CategoryID"] = 5;
                myIdDt.Rows.Add(myNewDr);

                myNewDr = myIdDt.NewRow();
                myNewDr["ID"] = "10000006";
                myNewDr["FullName"] = "demo006";
                myNewDr["CategoryID"] = 7.5;
                myIdDt.Rows.Add(myNewDr);
                
                int i = 0;

                //取整。
                object myObj = myIdDt.Compute("AVG(CategoryID)", "ID='10000005' ");

                myObj = myIdDt.Compute("AVG(CategoryID)", "ID='10000006' AND FullName='demo006' ");
                if (myObj != null)
                {
                    try
                    {
                        i = Convert.ToInt32(myObj.ToString());
                    }
                    catch (Exception myEx)
                    {
                        throw myEx;
                    }
                }

                //var temp1 = myIdDt.Compute("AVG(CategoryID)", "ID='10000006' AND FullName='demo006' ").ToString();
                //string temp2 = string.Empty;
            }
            catch (Exception myEx)
            {
                Common.WriteLogErr("myDataTableOp-GetDataTable:" + myEx.Message);
            }
            return myIdDt;
        }
        #endregion

        #region 获取数据库编号后续编码，适用于批量插入编号
        /// <summary>
        /// 获取数据库编号后续编码，适用于批量插入编号
        /// </summary>
        /// <param name="index">循环编号</param>
        /// <param name="curIndex">数据库GetCode获取的数据</param>
        /// <param name="preFix">前缀，如果为空默认时间：yyMMdd格式</param>
        /// <returns></returns>
        public static string GetCode(int index, string curIndex, string preFix = "")
        {
            int curentIndex = 0;
            if (curIndex.Length >= 3)
            {
                try
                {
                    curentIndex = Convert.ToInt32(curIndex.Substring(curIndex.Length - 3, 3));
                }
                catch //(Exception myEx)
                {
                    //myEx.Out("数据库GetCode获取的数据,转换成int 失败， GetCode:" + myEx);
                    curentIndex = 1;
                }
            }
            else if (curIndex.Length == 0)
            {
                return "";
            }
            else
            {
                return "";
            }

            string ret = string.Empty;
            try
            {
                string before = string.Empty;
                int result = index + curentIndex;
                switch (result.ToString().Length)
                {
                    case 3:
                        break;
                    case 2:
                        before = "0";
                        break;
                    case 1:
                        before = "00";
                        break;
                    default: break;
                }
                if (string.IsNullOrWhiteSpace(preFix))
                {
                    preFix = curIndex.Substring(0, curIndex.Length - 3);
                }
                ret = preFix + before + result.ToString();
            }
            catch //(Exception myEx)
            {
                //myEx.Out("CommonMethod-GetCode：" + myEx.Message);
            }
            return ret;
        }
        #endregion


        #region datatable.select (between and )
        /// <summary>
        /// DataTable 求最大值最小值
        /// </summary>
        /// <returns></returns>
        public DataTable GetDataTableOfDate()
        {
            DataTable myIdDt = new DataTable();
            try
            {
                DataRow myNewDr = null;
                myIdDt.Columns.AddRange(new DataColumn[] {
                new DataColumn("ID"),
                new DataColumn("FullName"),
                new DataColumn("Index"),
                //分类
                new DataColumn("CategoryID",typeof(int)),
                new DataColumn("StartDate", typeof(DateTime)),
                new DataColumn("EndDate",typeof(DateTime))
                });
                myNewDr = myIdDt.NewRow();
                myNewDr["ID"] = "10000001";
                myNewDr["FullName"] = "demo001";
                myNewDr["Index"] = 6;
                myNewDr["CategoryID"] = 2;
                myNewDr["StartDate"] = "2019-10-05";
                myNewDr["EndDate"] = "2019-10-06";
                myIdDt.Rows.Add(myNewDr);

                myNewDr = myIdDt.NewRow();
                myNewDr["ID"] = "10000002";
                myNewDr["FullName"] = "demo002";
                myNewDr["Index"] = 4;
                myNewDr["CategoryID"] = 1;
                myNewDr["StartDate"] = "2019-10-06";
                myNewDr["EndDate"] = "2019-10-07";

                myIdDt.Rows.Add(myNewDr);

                myNewDr = myIdDt.NewRow();
                myNewDr["ID"] = "10000003";
                myNewDr["FullName"] = "demo003";
                myNewDr["Index"] = 5;
                myNewDr["CategoryID"] = 0;
                myNewDr["StartDate"] = "2019-10-07";
                myNewDr["EndDate"] = "2019-10-07";
                myIdDt.Rows.Add(myNewDr);

                myNewDr = myIdDt.NewRow();
                myNewDr["ID"] = "10000002";
                myNewDr["FullName"] = "demo004";
                myNewDr["Index"] = 3;
                myNewDr["CategoryID"] = 3;
                myNewDr["StartDate"] = "2019-10-08";
                myNewDr["EndDate"] = "2019-10-10";
                myIdDt.Rows.Add(myNewDr);

                myNewDr = myIdDt.NewRow();
                myNewDr["ID"] = "10000005";
                myNewDr["FullName"] = "demo005";
                myNewDr["Index"] = 7;
                myNewDr["CategoryID"] = 2;
                myNewDr["StartDate"] = "2019-10-12";
                myNewDr["EndDate"] = "2019-10-16";

                myIdDt.Rows.Add(myNewDr);

                myNewDr = myIdDt.NewRow();
                myNewDr["ID"] = "10000006";
                myNewDr["FullName"] = "demo006";
                myNewDr["Index"] = 1;
                myNewDr["CategoryID"] = 3;
                myNewDr["StartDate"] = "2019-10-06";
                myNewDr["EndDate"] = "2019-10-06";
                myIdDt.Rows.Add(myNewDr);

            }
            catch (Exception myEx)
            {
                Common.WriteLogErr("myDataTableOp-GetDataTable:" + myEx.Message);
            }
            return myIdDt;
        }
        #endregion

        #region DataTable filter 过滤功能
        public DataTable GetFilterDt()
        {
            DataTable myDt = new DataTable();
            //dt.DefaultView.RowFilter = "Type = 0 or Type = 1 or Type = 2";
            //dt.DefaultView.Sort = "WeekDay,CourseIndex";
            try
            {
                myDt = GetDataTable();
                myDt.DefaultView.RowFilter = " CategoryID=0 or CategoryID=1 ";
                myDt.DefaultView.Sort = " CategoryID ";
                myDt = myDt.DefaultView.ToTable();
                //dt.DefaultView.RowFilter = "Type = 0 or Type = 1 or Type = 2";
            }
            catch (Exception myEx)
            {
                throw myEx;
            }
            return myDt;
        }
        #endregion

        #region indexof
        public void GetIndexOf()
        {
            try
            {
                //DataTable 1
                DataTable dt1 = new DataTable();
                dt1.Columns.Add("ID", typeof(int));
                dt1.Columns.Add("AnotherID", typeof(int));
                dt1.Columns.Add("Content", typeof(string));
                dt1.PrimaryKey = new[] { dt1.Columns["ID"] };

                // Add data
                dt1.Rows.Add(1, 10, "一年级,二年级");
                dt1.Rows.Add(2, 11, "二年级,三年级");
                dt1.Rows.Add(3, 12, "三年级,四年级");
                dt1.Rows.Add(4, 13, "四年级,五年级,六年级");
                dt1.Rows.Add(5, 14, "五年级,六年级");

                //DataTable 2 with the same schema as DataTable 1
                DataTable dt2 = new DataTable();
                dt2.Columns.Add("ID", typeof(int));
                dt2.Columns.Add("AnotherID", typeof(int));
                dt2.Columns.Add("Content", typeof(string));
                dt2.PrimaryKey = new[] { dt2.Columns["ID"] };

                // Add SAME data as DataTable 1
                dt2.Rows.Add(1, 10, "1");
                dt2.Rows.Add(2, 11, "2");
                dt2.Rows.Add(3, 12, "3");
                dt2.Rows.Add(4, 13, "4");
                dt2.Rows.Add(5, 14, "5");


                DataRow[] myTempDrs = dt1.Select("Content like '%一年级%'");

                //Select rows form DataTable dt2, using which populate DataRow[] rows
                DataRow[] rows = dt2.Select();

                //Then from the DataRow[] rows assign a random row (for example the first row) to a DataRow object
                DataRow row = rows[0];

                //Find the matching index of the DataRow object in DataTable dt1
                int index = dt1.Rows.IndexOf(row);

                //Console.WriteLine(index); // -1 Why on earth???? 
                //Console.ReadKey();
            }
            catch (Exception myEx)
            {
                throw myEx;
            }
        }
        #endregion

        #region Math.Round() 保留小数后 n 位
        public static double CutDecimalWithN(double d, int n)
        {
            string strDecimal = d.ToString();
            int index = strDecimal.IndexOf(".");
            if (index == -1 || strDecimal.Length < index + n + 1)
            {
                strDecimal = string.Format("{0:F" + n + "}", d);
            }
            else
            {
                int length = index;
                if (n != 0)
                {
                    length = index + n + 1;
                }
                strDecimal = strDecimal.Substring(0, length);
            }
            return Double.Parse(strDecimal);
        }

        public void Math_Round(double param, int n)
        {
            try
            {

                double ClassCourseTotalScore = 3877;
                double RealTackExam = 40.0;
                var AverageScore = Math.Round((decimal)(ClassCourseTotalScore / (RealTackExam == 0 ? 1 : RealTackExam)), 2, MidpointRounding.AwayFromZero);

                // Math.Round 用法，保留小数位，是否四舍五入
                var score = Math.Round((decimal)91.555);
                var t1 = Math.Round(Convert.ToDouble("96.12") - Convert.ToDouble("96.13"), 2, MidpointRounding.AwayFromZero);
                string AverageScoreDValue = CutDecimalWithN((Convert.ToDouble("96.12") - Convert.ToDouble("96.13")), 2).ToString();
            }
            catch (Exception myEx)
            {
                throw myEx;
            }
        }
        #endregion

        #region 【版本1】生成有规则的序列数据 字符串拼接 - 男生50米跑单项评分表
        public static string GenerateHtml(string startScore, string gradeName, string gradeBaseId)
        {
            string result = string.Empty;
            string type = string.Empty; //1升序，2降序

            if (string.IsNullOrWhiteSpace(gradeName))
            {
                gradeName = "一年级";
            }
            try
            {
                string tempHead = "{\"GradeBaseID\":\"" + gradeBaseId + "\",\"GradeName\":\"" + gradeName + "\",\"Scores\":[";
                int loop = 20;

                double dMinScore = 0;
                double dStartScore = 10.2;
                if (!string.IsNullOrWhiteSpace(startScore))
                {
                    dStartScore = Convert.ToDouble(startScore);
                }

                int iStartPerScore = 100;

                string loopData = string.Empty;
                for (int i = 0; i < loop; i++)
                {
                    if (loopData.Length == 0)
                    {
                        loopData = "{"
                           + "\"MinScore\":0,";
                    }
                    else
                    {
                        loopData += ",";
                        loopData += "{"
                       + "\"MinScore\":" + Math.Round(dMinScore, 1) + ",";
                    }
                    loopData += "\"MaxScore\":" + Math.Round(dStartScore, 1) + ","
                        + "\"Score\":\"" + iStartPerScore + "\""
                        + "}";

                    dMinScore = dStartScore;
                    if (i < 4)
                    {
                        iStartPerScore -= 5;
                        dStartScore += 0.1;
                    }
                    else if (i < 14)
                    {
                        iStartPerScore -= 2;
                        dStartScore += 0.2;
                    }
                    else if (i < 20)
                    {
                        iStartPerScore -= 10;
                        dStartScore += 0.2;
                    }
                }

                result = tempHead + loopData;
                result += ","
                    + "{"
                            + "\"MinScore\":" + Math.Round(dMinScore, 1) + ","
                            + "\"MaxScore\":99.0,"
                            + "\"Score\":\"" + iStartPerScore + "\""
                       + "}";

                result += "]}";
            }
            catch (Exception myEx)
            {
                throw myEx;
            }
            return result;
        }
        #endregion

        #region 【版本2】生成有规则的序列数据 字符串拼接 - 女生50米跑单项评分表
        public static string GenerateGirlHtml(string startScore, string gradeName, string gradeBaseId)
        {
            string result = string.Empty;
            string type = string.Empty; //1升序，2降序

            if (string.IsNullOrWhiteSpace(gradeName))
            {
                gradeName = "一年级";
            }

            //得分步进
            List<double> myList = new List<double> { 0.1, 0.3, 0.2, 0.2 };
            //百分比得分步进
            List<int> myScoreList = new List<int> { 5, 5, 2, 10 };

            //个数
            //List<int> myNumList = new List<int> { 3, 2, 10, 5 };
            List<int> myNumList = new List<int> { 3, 5, 15, 20 };

            try
            {
                string tempHead = "{\"GradeBaseID\":\"" + gradeBaseId + "\",\"GradeName\":\"" + gradeName + "\",\"Scores\":[";
                int loop = 20;

                double dMinScore = 0;
                double dStartScore = 10.2;
                if (!string.IsNullOrWhiteSpace(startScore))
                {
                    dStartScore = Convert.ToDouble(startScore);
                }

                int iStartPerScore = 100;

                string loopData = string.Empty;


                for (int i = 0; i < loop; i++)
                {
                    if (loopData.Length == 0)
                    {
                        loopData = "{"
                           + "\"MinScore\":0,";
                    }
                    else
                    {
                        loopData += ",";
                        loopData += "{"
                       + "\"MinScore\":" + Math.Round(dMinScore, 1) + ",";
                    }
                    loopData += "\"MaxScore\":" + Math.Round(dStartScore, 1) + ","
                        + "\"Score\":\"" + iStartPerScore + "\""
                        + "}";

                    dMinScore = dStartScore;


                    for (int rowNum = 0; rowNum < myNumList.Count(); rowNum++)
                    {
                        if ((i + 2) <= myNumList[rowNum])
                        {
                            iStartPerScore = iStartPerScore - myScoreList[rowNum];
                            dStartScore = dStartScore + myList[rowNum];
                            break;
                        }
                    }

                    //if (i < 4)
                    //{
                    //    iStartPerScore -= 5;
                    //    dStartScore += 0.1;
                    //}
                    //else if (i < 14)
                    //{
                    //    iStartPerScore -= 2;
                    //    dStartScore += 0.2;
                    //}
                    //else if (i < 20)
                    //{
                    //    iStartPerScore -= 10;
                    //    dStartScore += 0.2;
                    //}
                }

                result = tempHead + loopData;
                result += ","
                    + "{"
                            + "\"MinScore\":" + Math.Round(dMinScore, 1) + ","
                            + "\"MaxScore\":99.0,"
                            + "\"Score\":\"0\""
                       + "}";

                result += "]}";
            }
            catch (Exception myEx)
            {
                throw myEx;
            }
            return result;
        }
        #endregion

        #region 【版本3】生成有规则的序列数据 字符串拼接 - 女生50米跑单项评分表
        public static string GenerateTemplateHtml(string startScore, string gradeName, string gradeBaseId, List<double> myList, List<int> myScoreList, List<int> myNumList, string symbol)
        {
            string result = string.Empty;
            string type = string.Empty; //1降序，2升序

            if (string.IsNullOrWhiteSpace(gradeName))
            {
                gradeName = "一年级";
            }
            try
            {
                string tempHead = "{\"GradeBaseID\":\"" + gradeBaseId + "\",\"GradeName\":\"" + gradeName + "\",\"Scores\":[";
                int loop = 20;

                double dMinScore = 0;
                double dStartScore = 10.2;
                if (!string.IsNullOrWhiteSpace(startScore))
                {
                    dStartScore = Convert.ToDouble(startScore);
                }

                int iStartPerScore = 100;

                string loopData = string.Empty;


                for (int i = 0; i < loop; i++)
                {
                    if (loopData.Length == 0)
                    {
                        loopData = "{";

                        if (symbol == "1")
                        {
                            loopData += "\"MinScore\":199,";
                        }
                        else if (symbol == "2")
                        {
                            loopData += "\"MinScore\":0,";
                        }

                        //loopData = "{"
                        //   + "\"MinScore\":0,";
                    }
                    else
                    {
                        loopData += ",";
                        loopData += "{"
                       + "\"MinScore\":" + Math.Round(dMinScore, 1) + ",";
                    }
                    loopData += "\"MaxScore\":" + Math.Round(dStartScore, 1) + ","
                        + "\"Score\":\"" + iStartPerScore + "\""
                        + "}";

                    dMinScore = dStartScore;


                    for (int rowNum = 0; rowNum < myNumList.Count(); rowNum++)
                    {
                        if ((i + 2) <= myNumList[rowNum])
                        {
                            iStartPerScore = iStartPerScore - myScoreList[rowNum];
                            //降序
                            if (symbol == "1")
                            {
                                dStartScore = dStartScore - myList[rowNum];
                            }
                            else if (symbol == "2")
                            {
                                //升序
                                dStartScore = dStartScore + myList[rowNum];
                            }
                            break;
                        }
                    }

                    //if (i < 4)
                    //{
                    //    iStartPerScore -= 5;
                    //    dStartScore += 0.1;
                    //}
                    //else if (i < 14)
                    //{
                    //    iStartPerScore -= 2;
                    //    dStartScore += 0.2;
                    //}
                    //else if (i < 20)
                    //{
                    //    iStartPerScore -= 10;
                    //    dStartScore += 0.2;
                    //}
                }

                result = tempHead + loopData;
                result += ","
                    + "{"
                            + "\"MinScore\":" + Math.Round(dMinScore, 1) + ",";
                if (symbol == "1")
                {
                    result += "\"MaxScore\":0,";
                }
                else if (symbol == "2")
                {
                    result += "\"MaxScore\":199.0,";
                }
                result += "\"Score\":\"0\""
                       + "}";

                result += "]}";
            }
            catch (Exception myEx)
            {
                throw myEx;
            }
            return result;
        }
        #endregion

        #region 男生50米跑单项评分表 json
        public static string ForGenerateHtml_Man()
        {
            string result = string.Empty;
            string dd = string.Empty;
            try
            {
                dd += "["
                    + "{"
                    + "\"Project\":\"男生50米跑\","
                    + "\"ProjectCode\":\"ManMeters\","
                    + "\"CompareRule\":\"F\","
                    + "\"Grades\":[";
                List<string> myList = new List<string> { "一年级", "二年级", "三年级", "四年级", "五年级", "六年级" };
                List<string> myIdList = new List<string> { "10000010", "10000011", "10000012", "10000013", "10000014", "10000015" };
                double dStartDate = 10.2;
                for (int i = 0; i < 6; i++)
                {
                    if (result.Length == 0)
                    {
                        result = GenerateHtml(Math.Round(dStartDate, 1, MidpointRounding.AwayFromZero).ToString(), myList[i], myIdList[i]);
                    }
                    else
                    {
                        result += "," + GenerateHtml(Math.Round(dStartDate, 1, MidpointRounding.AwayFromZero).ToString(), myList[i], myIdList[i]);
                    }

                    dStartDate = dStartDate - 0.6 + i * 0.1;
                }
                dd += result += "]}]";

            }
            catch (Exception myEx)
            {
                throw myEx;
            }
            return result;
        }
        #endregion

        #region 女生50米跑单项评分表 json
        public static string ForGenerateHtml_Woman()
        {
            string result = string.Empty;
            string target = string.Empty;
            try
            {
                target += "["
                    + "{"
                    + "\"Project\":\"女生50米跑\","
                    + "\"ProjectCode\":\"WomanMeters\","
                    + "\"CompareRule\":\"F\","
                    + "\"Grades\":[";
                List<string> myList = new List<string> { "一年级", "二年级", "三年级", "四年级", "五年级", "六年级" };
                List<string> myIdList = new List<string> { "10000010", "10000011", "10000012", "10000013", "10000014", "10000015" };
                List<double> myScoreList = new List<double> { 11.0, 10.0, 9.2, 8.7, 8.3, 8.2 };
                for (int i = 0; i < 6; i++)
                {
                    if (result.Length == 0)
                    {
                        result = GenerateGirlHtml(Math.Round(myScoreList[i], 1, MidpointRounding.AwayFromZero).ToString(), myList[i], myIdList[i]);
                    }
                    else
                    {
                        result += "," + GenerateGirlHtml(Math.Round(myScoreList[i], 1, MidpointRounding.AwayFromZero).ToString(), myList[i], myIdList[i]);
                    }

                }
                target += result += "]}]";

            }
            catch (Exception myEx)
            {
                throw myEx;
            }
            return target;
        }
        #endregion

        #region 男生坐位体前屈单项评分表 json
        public static string ForGenerateHtml_Woman_ZWTQQ()
        {
            string result = string.Empty;
            string target = string.Empty;
            try
            {
                target += "["
                    + "{"
                    + "\"Project\":\"男生坐位体前屈\","
                    + "\"ProjectCode\":\"WomanMeters\","
                    + "\"CompareRule\":\"Z\","
                    + "\"Grades\":[";
                List<string> myList = new List<string> { "一年级", "二年级", "三年级", "四年级", "五年级", "六年级" };
                List<string> myIdList = new List<string> { "10000010", "10000011", "10000012", "10000013", "10000014", "10000015" };
                List<double> myScoreList = new List<double> { 11.0, 10.0, 9.2, 8.7, 8.3, 8.2 };

                //得分步进
                List<double> myMarkList = new List<double> { 1.5, 0.3, 0.2, 0.2 };
                //百分制得分步进
                List<int> myScoreStepList = new List<int> { 5, 5, 2, 10 };
                //个数
                List<int> myNumList = new List<int> { 3, 5, 15, 20 };

                string paramSymble = "1";

                for (int i = 0; i < 6; i++)
                {
                    if (result.Length == 0)
                    {
                        result = GenerateTemplateHtml(Math.Round(myScoreList[i], 1, MidpointRounding.AwayFromZero).ToString(), myList[i], myIdList[i], myMarkList, myScoreStepList, myNumList, paramSymble);
                    }
                    else
                    {
                        result += "," + GenerateTemplateHtml(Math.Round(myScoreList[i], 1, MidpointRounding.AwayFromZero).ToString(), myList[i], myIdList[i], myMarkList, myScoreStepList, myNumList, paramSymble);
                    }

                }
                target += result += "]}]";

            }
            catch (Exception myEx)
            {
                throw myEx;
            }
            return target;
        }
        #endregion

        #region 男生坐位体前屈单项评分表 json
        public static string ForGenerateHtml_Boy_1MinYWQZ()
        {
            string result = string.Empty;
            string target = string.Empty;
            try
            {
                target += "["
                    + "{"
                    + "\"Project\":\"男生一分钟仰卧起坐\","
                    + "\"ProjectCode\":\"BoyMeters\","
                    + "\"CompareRule\":\"Z\","
                    + "\"Grades\":[";
                //List<string> myList = new List<string> { "一年级", "二年级", "三年级", "四年级", "五年级", "六年级" };
                //List<string> myIdList = new List<string> { "10000010", "10000011", "10000012", "10000013", "10000014", "10000015" };
                List<string> myList = new List<string> { "三年级", "四年级", "五年级", "六年级" };
                List<string> myIdList = new List<string> { "10000012", "10000013", "10000014", "10000015" };
                List<double> myScoreList = new List<double> { 46, 47, 48, 49 };

                //百分制得分步进
                List<int> myScoreStepList = new List<int> { 5, 5, 2, 10 };

                //得分步进
                List<double> myMarkList = new List<double> { 3, 3, 2, 2 };

                //个数
                List<int> myNumList = new List<int> { 3, 5, 15, 20 };

                //计算符号1 + ；2 -
                string paramSymbol = "1";
                for (int i = 0; i < myList.Count(); i++)
                {
                    if (result.Length == 0)
                    {
                        result = GenerateTemplateHtml(Math.Round(myScoreList[i], 1, MidpointRounding.AwayFromZero).ToString(), myList[i], myIdList[i], myMarkList, myScoreStepList, myNumList, paramSymbol);
                    }
                    else
                    {
                        result += "," + GenerateTemplateHtml(Math.Round(myScoreList[i], 1, MidpointRounding.AwayFromZero).ToString(), myList[i], myIdList[i], myMarkList, myScoreStepList, myNumList, paramSymbol);
                    }

                }
                target += result += "]}]";

            }
            catch (Exception myEx)
            {
                throw myEx;
            }
            return target;
        }
        #endregion

        #region 女生坐位体前屈单项评分表 json
        public static string ForGenerateHtml_Girl_1MinYWQZ()
        {
            string result = string.Empty;
            string target = string.Empty;
            try
            {
                target += "["
                    + "{"
                    + "\"Project\":\"女生一分钟仰卧起坐\","
                    + "\"ProjectCode\":\"WomanMeters\","
                    + "\"CompareRule\":\"Z\","
                    + "\"Grades\":[";
                //List<string> myList = new List<string> { "一年级", "二年级", "三年级", "四年级", "五年级", "六年级" };
                //List<string> myIdList = new List<string> { "10000010", "10000011", "10000012", "10000013", "10000014", "10000015" };
                List<string> myList = new List<string> { "三年级", "四年级", "五年级", "六年级" };
                List<string> myIdList = new List<string> { "10000012", "10000013", "10000014", "10000015" };
                List<double> myScoreList = new List<double> { 46, 47, 48, 49 };

                //百分制得分步进
                List<int> myScoreStepList = new List<int> { 5, 5, 2, 10 };

                //得分步进
                List<double> myMarkList = new List<double> { 2, 3, 2, 2 };

                //个数
                List<int> myNumList = new List<int> { 3, 5, 15, 20 };

                //计算符号1 + ；2 -
                string paramSymbol = "1";
                for (int i = 0; i < myList.Count(); i++)
                {
                    if (result.Length == 0)
                    {
                        result = GenerateTemplateHtml(Math.Round(myScoreList[i], 1, MidpointRounding.AwayFromZero).ToString(), myList[i], myIdList[i], myMarkList, myScoreStepList, myNumList, paramSymbol);
                    }
                    else
                    {
                        result += "," + GenerateTemplateHtml(Math.Round(myScoreList[i], 1, MidpointRounding.AwayFromZero).ToString(), myList[i], myIdList[i], myMarkList, myScoreStepList, myNumList, paramSymbol);
                    }

                }
                target += result += "]}]";

            }
            catch (Exception myEx)
            {
                throw myEx;
            }
            return target;
        }
        #endregion

        #region 女生一分钟跳绳单向评分表 json
        public static string ForGenerateHtml_Girl_1MinTS()
        {
            string result = string.Empty;
            string target = string.Empty;
            try
            {
                target += "["
                    + "{"
                    + "\"Project\":\"女生一分钟跳绳\","
                    + "\"ProjectCode\":\"WomanMeters\","
                    + "\"CompareRule\":\"Z\","
                    + "\"Grades\":[";
                List<string> myList = new List<string> { "一年级", "二年级", "三年级", "四年级", "五年级", "六年级" };
                List<string> myIdList = new List<string> { "10000010", "10000011", "10000012", "10000013", "10000014", "10000015" };
                List<double> myScoreList = new List<double> { 117, 127, 139, 149, 158, 166 };

                //百分制得分步进
                List<int> myScoreStepList = new List<int> { 5, 5, 2, 10 };

                //得分步进
                List<double> myMarkList = new List<double> { 7, 8, 7, 3 };

                //个数
                List<int> myNumList = new List<int> { 3, 5, 15, 20 };

                //计算符号1 + ；2 -
                string paramSymbol = "1";
                for (int i = 0; i < 6; i++)
                {
                    if (result.Length == 0)
                    {
                        result = GenerateTemplateHtml(Math.Round(myScoreList[i], 1, MidpointRounding.AwayFromZero).ToString(), myList[i], myIdList[i], myMarkList, myScoreStepList, myNumList, paramSymbol);
                    }
                    else
                    {
                        result += "," + GenerateTemplateHtml(Math.Round(myScoreList[i], 1, MidpointRounding.AwayFromZero).ToString(), myList[i], myIdList[i], myMarkList, myScoreStepList, myNumList, paramSymbol);
                    }

                }
                target += result += "]}]";

            }
            catch (Exception myEx)
            {
                throw myEx;
            }
            return target;
        }
        #endregion

        #region 男生一分钟跳绳单向评分表 json
        public static string ForGenerateHtml_Boy_1MinTS()
        {
            string result = string.Empty;
            string target = string.Empty;
            try
            {
                target += "["
                    + "{"
                    + "\"Project\":\"男生一分钟跳绳\","
                    + "\"ProjectCode\":\"WomanMeters\","
                    + "\"CompareRule\":\"Z\","
                    + "\"Grades\":[";
                List<string> myList = new List<string> { "一年级", "二年级", "三年级", "四年级", "五年级", "六年级" };
                List<string> myIdList = new List<string> { "10000010", "10000011", "10000012", "10000013", "10000014", "10000015" };
                List<double> myScoreList = new List<double> { 109, 117, 126, 137, 148, 157 };

                //百分制得分步进
                List<int> myScoreStepList = new List<int> { 5, 5, 2, 10 };

                //得分步进
                List<double> myMarkList = new List<double> { 5, 6, 7, 3 };

                //个数
                List<int> myNumList = new List<int> { 3, 5, 15, 20 };

                //计算符号1 + ；2 -
                string paramSymbol = "1";
                for (int i = 0; i < 6; i++)
                {
                    if (result.Length == 0)
                    {
                        result = GenerateTemplateHtml(Math.Round(myScoreList[i], 1, MidpointRounding.AwayFromZero).ToString(), myList[i], myIdList[i], myMarkList, myScoreStepList, myNumList, paramSymbol);
                    }
                    else
                    {
                        result += "," + GenerateTemplateHtml(Math.Round(myScoreList[i], 1, MidpointRounding.AwayFromZero).ToString(), myList[i], myIdList[i], myMarkList, myScoreStepList, myNumList, paramSymbol);
                    }

                }
                target += result += "]}]";

            }
            catch (Exception myEx)
            {
                throw myEx;
            }
            return target;
        }
        #endregion

        #region DataTable.Select Not in 数据条件排除
        public void DataTableRemoveV2()
        {
            try
            {
                DataTable myDt = this.GetDataTable();
                DataTable myDtOther = this.GetDataTableOther();
                DataRow[] myDrs = myDt.Select(string.Format("{0}='{1}'", "CategoryID", "1"));
                if (myDrs.Length > 0)
                {
                    myDt = myDrs.CopyToDataTable();
                }

                DataRow[] myDrs1 = myDtOther.Select(string.Format("{0}='{1}'", "CategoryID", "1"));
                int len = myDrs1.Length;
                string[] exclude = new string[len];
                for (int i = 0; i < len; i++)
                {
                    exclude[i] = myDrs1[i]["ID"].ToString();
                }

                DataTable result = myDt.AsEnumerable().Where(r => !exclude.Contains(r["ID"])).CopyToDataTable();
            }
            catch (Exception myEx)
            {
                Common.WriteLogErr(myEx.Message);
            }
        }
        #endregion

        #region DataTable.Compute
        /// <summary>
        /// 计算DataTable 最大值和最小值
        /// </summary>
        public void DataTableComput()
        {
            try
            {
                string maxScore = string.Empty;
                string minScore = string.Empty;
                DataTable myDt = this.GetDataTable();
                object myObj = myDt.Compute("MAX(" + "Score" + ")", "1=1");
                if (myObj != null && myObj.ToString() != "")
                {
                    maxScore = myObj.ToString();
                }

                myObj = myDt.Compute("MIN(" + "Score" + ")", "1=0");
                if (myObj != null && myObj.ToString() != "")
                {
                    minScore = myObj.ToString();
                }
                string tt = string.Empty;
                tt = "";
            }
            catch (Exception myEx)
            {
                Common.WriteLogErr(myEx.Message);
            }
        }
        #endregion

        #region 去除字段最后一个值
        public void strTrimEnd()
        {
            DataTable myDt = new DataTable();
            myDt.Columns.AddRange(new DataColumn[] {
                new DataColumn("ID", typeof(string)),
                new DataColumn("Name", typeof(string)),
                new DataColumn("Enabled", typeof(string)),
                new DataColumn("Remark", typeof(string))
            });


            DataRow[] myDrs = myDt.Select("1=1");
            if (myDrs.Length == 0)
            {
                object myCopyDr = myDrs.Clone();
            }
            string tt = "0.5000";
            string result = tt.TrimEnd('0');

            tt = "1.0000";
            result = tt.TrimEnd('0').TrimEnd('.');
            if (result.Substring(result.Length - 1, 1) == ".")
            {
                result = result.ToString() + '0';
            }

            string recv = string.Empty;

        }
        #endregion

        #region 获取首字母大写
        /// <summary>
        /// 获得字符串首字符字母（大写）；
        /// </summary>
        /// <param name="cnChar"></param>
        /// <returns></returns>
        public string GetStringFirstSpell(string cnChar)
        {
            //除字母、数字、汉字以外的返回"*"
            var result = "*";

            if (string.IsNullOrEmpty(cnChar.Trim()))
                return result;

            cnChar = cnChar.Trim().Substring(0, 1);
            byte[] arrCn = Encoding.Default.GetBytes(cnChar);

            //首字为字符,占一个字节
            if (arrCn.Length <= 1)
            {
                //大写英文字母
                if ((short)arrCn[0] >= 65 && (short)arrCn[0] <= 90)
                    return cnChar;

                //小写英文字母
                if (arrCn[0] >= 97 && arrCn[0] <= 122)
                    return Encoding.Default.GetString(new byte[] { (byte)((short)arrCn[0] - 32) });

                //数字
                switch (cnChar)
                {
                    case "1":
                        result = "Y";
                        break;
                    case "2":
                        result = "E";
                        break;
                    case "3":
                    case "4":
                        result = "S";
                        break;
                    case "5":
                        result = "W";
                        break;
                    case "0":
                    case "6":
                        result = "L";
                        break;
                    case "7":
                        result = "Q";
                        break;
                    case "8":
                        result = "B";
                        break;
                    case "9":
                        result = "J";
                        break;
                }
                return result;
            }
            //首字为汉字,占两个字节
            else
            {
                int area = (short)arrCn[0];
                int pos = (short)arrCn[1];
                int code = (area << 8) + pos;
                int[] areacode = { 45217, 45253, 45761, 46318, 46826, 47010, 47297, 47614, 48119, 48119, 49062, 49324, 49896, 50371, 50614, 50622, 50906, 51387, 51446, 52218, 52698, 52698, 52698, 52980, 53689, 54481 };
                for (int i = 0; i < 26; i++)
                {
                    int max = 55290;
                    if (i != 25) max = areacode[i + 1];
                    if (areacode[i] <= code && code < max)
                    {
                        return Encoding.Default.GetString(new byte[] { (byte)(65 + i) });
                    }
                }
                return result;
            }
        }

        /// <summary> 
        /// 在指定的字符串列表CnStr中检索符合拼音索引字符串 
        /// </summary> 
        /// <param name="CnStr">汉字字符串</param> 
        /// <returns>相对应的汉语拼音首字母串</returns> 
        public static string GetSpellCode(string CnStr)
        {
            string strTemp = "";
            int iLen = CnStr.Length;
            int i = 0;

            for (i = 0; i <= iLen - 1; i++)
            {
                strTemp += GetCharSpellCode(CnStr.Substring(i, 1));
            }

            return strTemp;
        }


        /// <summary> 
        /// 得到一个汉字的拼音第一个字母，如果是一个英文字母则直接返回大写字母 
        /// </summary> 
        /// <param name="CnChar">单个汉字</param> 
        /// <returns>单个大写字母</returns> 
        private static string GetCharSpellCode(string CnChar)
        {
            long iCnChar;

            byte[] ZW = System.Text.Encoding.Default.GetBytes(CnChar);

            //如果是字母，则直接返回 
            if (ZW.Length == 1)
            {
                return CnChar.ToUpper();
            }
            else
            {
                // get the array of byte from the single char 
                int i1 = (short)(ZW[0]);
                int i2 = (short)(ZW[1]);
                iCnChar = i1 * 256 + i2;
            }

            //expresstion 
            //table of the constant list 
            // 'A'; //45217..45252 
            // 'B'; //45253..45760 
            // 'C'; //45761..46317 
            // 'D'; //46318..46825 
            // 'E'; //46826..47009 
            // 'F'; //47010..47296 
            // 'G'; //47297..47613 

            // 'H'; //47614..48118 
            // 'J'; //48119..49061 
            // 'K'; //49062..49323 
            // 'L'; //49324..49895 
            // 'M'; //49896..50370 
            // 'N'; //50371..50613 
            // 'O'; //50614..50621 
            // 'P'; //50622..50905 
            // 'Q'; //50906..51386 

            // 'R'; //51387..51445 
            // 'S'; //51446..52217 
            // 'T'; //52218..52697 
            //没有U,V 
            // 'W'; //52698..52979 
            // 'X'; //52980..53640 
            // 'Y'; //53689..54480 
            // 'Z'; //54481..55289 

            // iCnChar match the constant 
            if ((iCnChar >= 45217) && (iCnChar <= 45252))
            {
                return "A";
            }
            else if ((iCnChar >= 45253) && (iCnChar <= 45760))
            {
                return "B";
            }
            else if ((iCnChar >= 45761) && (iCnChar <= 46317))
            {
                return "C";
            }
            else if ((iCnChar >= 46318) && (iCnChar <= 46825))
            {
                return "D";
            }
            else if ((iCnChar >= 46826) && (iCnChar <= 47009))
            {
                return "E";
            }
            else if ((iCnChar >= 47010) && (iCnChar <= 47296))
            {
                return "F";
            }
            else if ((iCnChar >= 47297) && (iCnChar <= 47613))
            {
                return "G";
            }
            else if ((iCnChar >= 47614) && (iCnChar <= 48118))
            {
                return "H";
            }
            else if ((iCnChar >= 48119) && (iCnChar <= 49061))
            {
                return "J";
            }
            else if ((iCnChar >= 49062) && (iCnChar <= 49323))
            {
                return "K";
            }
            else if ((iCnChar >= 49324) && (iCnChar <= 49895))
            {
                return "L";
            }
            else if ((iCnChar >= 49896) && (iCnChar <= 50370))
            {
                return "M";
            }

            else if ((iCnChar >= 50371) && (iCnChar <= 50613))
            {
                return "N";
            }
            else if ((iCnChar >= 50614) && (iCnChar <= 50621))
            {
                return "O";
            }
            else if ((iCnChar >= 50622) && (iCnChar <= 50905))
            {
                return "P";
            }
            else if ((iCnChar >= 50906) && (iCnChar <= 51386))
            {
                return "Q";
            }
            else if ((iCnChar >= 51387) && (iCnChar <= 51445))
            {
                return "R";
            }
            else if ((iCnChar >= 51446) && (iCnChar <= 52217))
            {
                return "S";
            }
            else if ((iCnChar >= 52218) && (iCnChar <= 52697))
            {
                return "T";
            }
            else if ((iCnChar >= 52698) && (iCnChar <= 52979))
            {
                return "W";
            }
            else if ((iCnChar >= 52980) && (iCnChar <= 53640))
            {
                return "X";
            }
            else if ((iCnChar >= 53689) && (iCnChar <= 54480))
            {
                return "Y";
            }
            else if ((iCnChar >= 54481) && (iCnChar <= 55289))
            {
                return "Z";
            }
            else return ("?");
        }
        #endregion

        #region GetDtAsDvForSort

        public void GetDtAsDvForSort() {
            //dv 排序
            DataTable myDt = new DataTable();
            myDt.Columns.AddRange(new DataColumn[] {
                 new DataColumn("ID", typeof(string)),
                 new DataColumn("CreateDate",typeof(string))
            });

            DataRow myNewDr = myDt.NewRow();
            myNewDr["ID"] = "5";
            myNewDr["CreateDate"] = "2020-06-01";
            myDt.Rows.Add(myNewDr);

            myNewDr = myDt.NewRow();
            myNewDr["ID"] = "1";
            myNewDr["CreateDate"] = "2020-06-02";
            myDt.Rows.Add(myNewDr);

            myNewDr = myDt.NewRow();
            myNewDr["ID"] = "6";
            myNewDr["CreateDate"] = "2020-06-02";
            myDt.Rows.Add(myNewDr);

            myNewDr = myDt.NewRow();
            myNewDr["ID"] = "2";
            myNewDr["CreateDate"] = "2020-07-01";
            myDt.Rows.Add(myNewDr);

            DataView myDv = myDt.AsDataView();
            myDv.Sort = "CreateDate Desc, ID Desc";
            myDv.Sort = "CreateDate asc";
            myDv.Sort = "ID Desc";
            myDv.Sort = "ID asc";
            string target = myDv[0]["CreateDate"].ToString();
            string tt = "";


            //int result = Convert.ToInt32(Math.Floor(9.6));

            //myDataTableOp.DataTableComput();

            //获取首字母大写

            //string getFirst ="芶";
            //string retVal = myDataTableOp.GetStringFirstSpell(getFirst);
            //retVal = DataTableOp.ChineseToPYAbbreviation(getFirst);
            //var tt = string.Empty;

            //获取时间范围内的日期列表
            //string paramStartDate = "2021-03-08";
            //string paramEndDate = "2021-03-07";

            //DataTable myDt = new DataTableOp().GetDateDt(paramStartDate, paramEndDate);
            //var tt = string.Empty;


            //var tt = DataTableOp.GetBirthDayAndGenderById("");


            //int month = DateTime.Now.Month;
            //var t1 = string.Empty;
        }
        #endregion


        public static string ChineseToPYAbbreviation(string str)
        {
            string tempStr = "";
            foreach (char c in str)
            {
                if ((int)c >= 33 && (int)c <= 126)
                {//字母和符号原样保留

                    tempStr += c.ToString();
                }
                else
                {//累加拼音声母
                    tempStr += GetPYChar(c.ToString());
                }
            }
            return tempStr;
        }
        /**/
        ///
        /// 取单个字符的拼音声母
        ///
        /// 要转换的单个汉字
        /// 拼音声母
        private static string GetPYChar(string c)
        {
            byte[] array = new byte[2];
            array = System.Text.Encoding.Default.GetBytes(c);
            int i = (short)(array[0] - '\0') * 256 + ((short)(array[1] - '\0'));

            if (i < 0xB0A1) return "*";
            if (i < 0xB0C5) return "a";
            if (i < 0xB2C1) return "b";
            if (i < 0xB4EE) return "c";
            if (i < 0xB6EA) return "d";
            if (i < 0xB7A2) return "e";
            if (i < 0xB8C1) return "f";
            if (i < 0xB9FE) return "g";
            if (i < 0xBBF7) return "h";
            if (i < 0xBFA6) return "j";
            if (i < 0xC0AC) return "k";
            if (i < 0xC2E8) return "l";
            if (i < 0xC4C3) return "m";
            if (i < 0xC5B6) return "n";
            if (i < 0xC5BE) return "o";
            if (i < 0xC6DA) return "p";
            if (i < 0xC8BB) return "q";
            if (i < 0xC8F6) return "r";
            if (i < 0xCBFA) return "s";
            if (i < 0xCDDA) return "t";
            if (i < 0xCEF4) return "w";
            if (i < 0xD1B9) return "x";
            if (i < 0xD4D1) return "y";
            if (i < 0xD7FA) return "z";
            return "*";
        }


        #region 获取指定时间隔的时间数据集合  youping 2021-03-12 17:09
        /// <summary>
        /// 获取指定时间隔的时间数据集合
        /// </summary>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        /// <param name="format"></param>
        /// <returns></returns>
        public DataTable GetDateDt(string startDate, string endDate, string format = "yyyy-MM-dd")
        {
            if (string.IsNullOrWhiteSpace(startDate) || string.IsNullOrWhiteSpace(endDate))
            {
                return null;
            }
            DataTable myDateDt = new DataTable();
            myDateDt.Columns.Add("Date", typeof(string));

            DateTime dStartDate;
            DateTime dEndDate;
            DataRow myNewDr = null;
            try
            {
                dStartDate = Convert.ToDateTime(startDate);
                dEndDate = Convert.ToDateTime(endDate);
                if (dEndDate < dStartDate)
                {
                    return null;
                }

                do
                {
                    myNewDr = myDateDt.NewRow();
                    myNewDr["Date"] = Convert.ToDateTime(dStartDate).ToString(format);
                    myDateDt.Rows.Add(myNewDr);
                    dStartDate = dStartDate.AddDays(1);
                }
                while (dStartDate <= dEndDate);
                return myDateDt;
            }
            catch
            {
                return null;
            }
        }

        #endregion

        #region DataTable IN 操作
        public bool GetDtInData()
        {
            DataTable myDt = GetDataTable();
            DataRow[] myDrs = myDt.Select(string.Format("{0} in ('{1}','{2}')", "CategoryID", "0", "2"));
            return myDrs.Length > 0;
        }
        #endregion

        #region GetDtSort
        public void GetDtSort()
        {
            try
            {
                DataTable myDt = GetDataTable();
                DataRow[] myDrs = myDt.Select(string.Format("{0}={1}", "CategoryID", "1"), "StartScore desc ");
                string temp = string.Empty;

            }
            catch (Exception ex)
            {
                Common.WriteLogErr(ex.Message);
            }

        }
        #endregion

        #region Datatable AsEnumerable 判断是否为空
        /// <summary>
        /// 判断是否为空
        /// </summary>
        public void CheckAsEnumerableCount()
        {
            try
            {
                DataTable myDt = GetDataTable();
                DataTable myNewDt = myDt.Clone();
                var tempList = myDt.AsEnumerable().Where(p => p["ID"].ToString() == "10000000");

                // 需要使用 using System.Linq; 引用才能计算个数
                int result = tempList.Count();
                if (result > 0)
                {
                    myNewDt = tempList.CopyToDataTable();
                }
            }
            catch (Exception ex) {
                throw ex;
            }
        }
        #endregion

        public class StudentBaseList
        {
            public string ID { set; get; }
            public string SemesterID { set; get; }
            public string GradeBaseID { set; get; }
            public string GradeName { set; get; }
            public string ClassBaseID { set; get; }
            public string ClassName { set; get; }
            public string StudentName { set; get; }
            /// <summary>
            /// 姓名拼音
            /// </summary>
            public string NamePinyin { set; get; }
            /// <summary>
            /// 学生所属学校
            /// </summary>
            public string StudentUnitID { set; get; }
            public string FormerName { set; get; }
            /// <summary>
            /// 全国唯一学籍号
            /// </summary>
            public string UniquenessCode { set; get; }
            public string UnitiveCode { set; get; }
            public string AuxiliaryCode { set; get; }
            public string StudentCode { set; get; }
            public string Gender { set; get; }
            public string Birthday { set; get; }
            public string StudentStatus { set; get; }
            public string CardNumber { set; get; }
            public string ToSchoolType { set; get; }
            public string TotalScore { set; get; }
            public string ToSchoolDate { set; get; }
            public string ToSchoolLevel { set; get; }
            public string Guardian { set; get; }
            public string GuardianRelation { set; get; }
            public string RelationTypeID { get; set; }
            public string GuardianMobile { set; get; }
            public string Birthplace { set; get; }
            public string Marriage { set; get; }
            public string Religious { set; get; }
            public string Email { set; get; }
            public string Nation { set; get; }
            public string BridgeOutside { set; get; }
            public string Nationality { set; get; }
            public string IdCardType { set; get; }
            public string IdentityNumber { set; get; }
            public string IDCardValid { set; get; }
            public string GraduateSchool { set; get; }
            public string StudentType { set; get; }
            public string PoliticallScape { set; get; }
            public string HealthStatus { set; get; }
            public string BloodType { set; get; }
            public string IsBoarder { set; get; }
            public string IsOnlyChild { set; get; }
            public string HomeAddress { set; get; }
            public string PostCode { set; get; }
            public string FamilyMobile { set; get; }
            public string Specialty { set; get; }
            public string Remark { set; get; }
            public string PhotoPath { set; get; }
            //扩展信息
            public string IsWithWorker { set; get; }
            public string IsRuralLeftBehind { set; get; }
            public string DutyEduNumber { set; get; }
            public string IsPreschoolEdu { set; get; }
            public string TestsNumber { set; get; }
            public string ChangeRemark { set; get; }
            public string ExtendRemark { set; get; }
            public string Province { set; get; }
            public string City { set; get; }
            public string Area { set; get; }
            public string CensusCommunity { set; get; }
            public string CensusDate { set; get; }
            public string CensusType { set; get; }
            public string NativePlace { set; get; }
            public string CensusRemark { set; get; }
            /// <summary>
            /// 当前操作人所属学校
            /// </summary>
            public string UnitID { set; get; }
            /// <summary>
            /// 当前操作人UserID
            /// </summary>
            public string Operator { set; get; }
            /// <summary>
            /// 是否孤儿 1是，0否
            /// </summary>
            public string IsOrphan { get; set; }
            /// <summary>
            /// 是否单亲家庭 1是，0否
            /// </summary>
            public string IsSingleFamily { get; set; }
            public int pageIndex { set; get; }
            public int pageSize { set; get; }
            public bool IsPaging { set; get; }
            /// <summary>
            /// 学段名称
            /// </summary>
            public string SectionName { get; set; }
            /// <summary>
            /// 性别名称
            /// </summary>
            public string GenderName { get; set; }
        }

        #region 验证身份证号码合法性 https://www.cnblogs.com/ChineseMoonGod/p/5193606.html
        private static bool CheckIDCard18(string idNumber)
        {
            long n = 0;
            if (long.TryParse(idNumber.Remove(17), out n) == false
                || n < Math.Pow(10, 16) || long.TryParse(idNumber.Replace('x', '0').Replace('X', '0'), out n) == false)
            {
                return false;//数字验证  
            }
            string address = "11x22x35x44x53x12x23x36x45x54x13x31x37x46x61x14x32x41x50x62x15x33x42x51x63x21x34x43x52x64x65x71x81x82x91";
            if (address.IndexOf(idNumber.Remove(2)) == -1)
            {
                return false;//省份验证  
            }
            string birth = idNumber.Substring(6, 8).Insert(6, "-").Insert(4, "-");
            DateTime time = new DateTime();
            if (DateTime.TryParse(birth, out time) == false)
            {
                return false;//生日验证  
            }
            string[] arrVarifyCode = ("1,0,x,9,8,7,6,5,4,3,2").Split(',');
            string[] Wi = ("7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2").Split(',');
            char[] Ai = idNumber.Remove(17).ToCharArray();
            int sum = 0;
            for (int i = 0; i < 17; i++)
            {
                sum += int.Parse(Wi[i]) * int.Parse(Ai[i].ToString());
            }
            int y = -1;
            Math.DivRem(sum, 11, out y);
            if (arrVarifyCode[y] != idNumber.Substring(17, 1).ToLower())
            {
                return false;//校验码验证  
            }
            return true;//符合GB11643-1999标准  
        }

        /// <summary>  
        /// 16位身份证号码验证  
        /// </summary>  
        private static bool CheckIDCard15(string idNumber)
        {
            long n = 0;
            if (long.TryParse(idNumber, out n) == false || n < Math.Pow(10, 14))
            {
                return false;//数字验证  
            }
            string address = "11x22x35x44x53x12x23x36x45x54x13x31x37x46x61x14x32x41x50x62x15x33x42x51x63x21x34x43x52x64x65x71x81x82x91";
            if (address.IndexOf(idNumber.Remove(2)) == -1)
            {
                return false;//省份验证  
            }
            string birth = idNumber.Substring(6, 6).Insert(4, "-").Insert(2, "-");
            DateTime time = new DateTime();
            if (DateTime.TryParse(birth, out time) == false)
            {
                return false;//生日验证  
            }
            return true;
        }
        #endregion

        #region Tuple 返回多个值
        public static Tuple<string, string> GetBirthDayAndGenderById(string id)
        {
            string result = string.Empty;
            if (string.IsNullOrWhiteSpace(id))
            {
                result = "身份证号码不能为空";
            }
            if (!CheckIDCard18(id))
            {
                result = "身份证号码输入错误，请检查";
            }


            try
            {
                if (!string.IsNullOrEmpty(id))
                {
                    if (id.Length > 18)
                    {
                        result = "不能大于18个字符";
                    }
                    Regex r = new Regex(@"^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$");
                    if (!r.IsMatch(id))
                    {
                        result = "不是有效的身份证格式";
                    }
                }

                if (result.Length == 0)
                {
                    string birthday = string.Empty;
                    string sex = string.Empty;
                    string sexName = string.Empty;
                    if (id.Length == 18)//处理18位的身份证号码从号码中得到生日和性别代码
                    {
                        birthday = id.Substring(6, 4) + "-" + id.Substring(10, 2) + "-" + id.Substring(12, 2);
                        sex = id.Substring(14, 3);
                    }
                    if (id.Length == 15)
                    {
                        birthday = "19" + id.Substring(6, 2) + "-" + id.Substring(8, 2) + "-" + id.Substring(10, 2);
                        sex = id.Substring(12, 3);
                    }

                    if (int.Parse(sex) % 2 == 0)//性别代码为偶数是女性奇数为男性
                    {
                        sexName = "女";
                    }
                    else
                    {
                        sexName = "男";
                    }

                    return Tuple.Create(birthday, sexName);
                }
                return null;
            }
            catch (Exception myEx)
            {
                throw myEx;
            }

        }
        #endregion

        #region DataTable 排除相等的值
        public string ExceptContainKey()
        {
            string result = string.Empty;
            try
            {
                DataTable myDt = this.GetDataTable();

                //备注不能将 <> 替换成 !=
                DataRow[] myDrs = myDt.Select(string.Format("{0}<>'{1}'", "CategoryID", "0"));
                if (myDrs.Length > 0)
                {
                    result = "1";
                }
                else
                {
                    result = "2";
                }

                DataTable myTempDt = myDt.AsEnumerable().Where(p => p["CategoryID"].ToString() != "0").CopyToDataTable();
                if (myTempDt.Rows.Count > 0)
                {
                    result = "1";
                }
                else
                {
                    result = "2";
                }
            }
            catch (Exception myEx)
            {
                Common.WriteLogErr(myEx.Message);
            }
            return result;
        }
        #endregion




    }

}
